package com.consult.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.consult.config.dto.AjaxResult;
import com.consult.entity.Consultant;
import com.consult.service.IConsultantService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-06-22
 */
@RestController
@RequestMapping("/consultant")
public class ConsultantController {

    @Resource
    private IConsultantService consultantService;

    @PostMapping("/add")
    public AjaxResult addConsultant(@RequestBody Consultant consultant) {
        if (StringUtils.isBlank(consultant.getPassword())) {
            consultant.setPassword("123456");
        }
        consultantService.save(consultant);
        return AjaxResult.success();
    }

    @PostMapping("/page")
    public AjaxResult consultantPage(@RequestBody Page<Consultant> page) {
        page = consultantService.getConsultantPage(page);
        return AjaxResult.success(page);
    }

    @PostMapping("/update")
    public AjaxResult updateConsultant(@RequestBody Consultant consultant) {
        consultantService.updateById(consultant);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult deleteConsultant(Long id) {
        consultantService.removeById(id);
        return AjaxResult.success();
    }

}

